package mobi.hami.huapin.dao;

import java.util.Map;

public class SubjectProvider {
    /**
     * 多条件搜索主题
     * @param parms
     * @return
     */
    public String selectSubjectsWitchParam(Map<String,Object> parms){
        StringBuilder sb = new StringBuilder();
        sb.append("select * from subject where ");
        if(null != parms.get("name") && !parms.get("name").equals("")){
            sb.append("name like '%").append(String.valueOf(parms.get("name"))).append("%'").append(" and ");
        }
        if(null != parms.get("use_status") && !parms.get("use_status").equals("")){
            sb.append("use_status = ").append(parms.get("use_status")).append(" and ");
        }
        if(null != parms.get("day_of_week") && !parms.get("day_of_week").equals("")){
            sb.append("day_of_week = ").append(parms.get("day_of_week")).append(" and ");
        }
        if(null != parms.get("description") && !parms.get("description").equals("")){
            sb.append("description like '%").append(String.valueOf(parms.get("description"))).append("%'").append(" and ");
        }
        if(null != parms.get("deleted") && !parms.get("deleted").equals("")){
            sb.append("deleted = ").append(parms.get("deleted")).append(" and ");
        }
        if(null != parms.get("start_gmt_create") && !parms.get("start_gmt_create").equals("")){
            sb.append("gmt_create >= '").append(parms.get("start_gmt_create").toString()).append("' and ");
        }
        if(null != parms.get("end_gmt_create") && !parms.get("end_gmt_create").equals("")){
            sb.append("gmt_create <= '").append(parms.get("end_gmt_create").toString()).append("' and ");
        }
        if(null != parms.get("start_gmt_modified") && !parms.get("start_gmt_modified").equals("")){
            sb.append("gmt_modified >= '").append(parms.get("start_gmt_modified").toString()).append("' and ");
        }
        if(null != parms.get("end_gmt_modified") && !parms.get("end_gmt_modified").equals("")){
            sb.append("gmt_modified <= '").append(parms.get("end_gmt_modified").toString()).append("' and ");
        }
        sb.append("1 = 1 ");
        sb.append("order by gmt_create,gmt_modified desc");
        return sb.toString();
    }
}
